import React, { useEffect, useState } from 'react'
import { useLocation, useParams, useSearchParams } from 'react-router-dom'
import axios from 'axios'
const Detail = () => {
  // 获取当前路由信息
  const location = useLocation()
  // 获取路由信息里的search
  const [searchParams] = useSearchParams()
  // const search = location.search.slice(1)
  // const [id,val] = search.split('=')
  // console.log(id,val)
  console.log(location)
  // get 获取具体某个  getAll 获取多个相同的 组成一个数组
  console.log(searchParams.get('id'))

  // 动态获取路由参数
  const params = useParams()  
  console.log(params)

  const [detailList, setDetailList] = useState([])
  const getDetail = async() => {
    const res = await axios.get('https://m.maizuo.com/gateway',{
      params: {
        // filmId:searchParams.get('id'),
        filmId:params.id,
        k:9685411
      },
      headers:{
          'x-client-info':'{"a":"3000","ch":"1002","v":"5.2.1","e":"173088338914639202754887681","bc":"110100"}',
          'x-host':'mall.film-ticket.film.info'
      }
    })
    console.log(res.data.data.film)
    setDetailList(res.data.data.film)
  }
  useEffect(() => {
    getDetail()
  },[])


  return (
    <div>
      <h3>{detailList.name}</h3>
      <img src={detailList.poster} width={200} alt="" />
    </div>
  )
}

export default Detail